package com.qingshu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qingshu.common.entity.custom.Album;
import com.qingshu.common.util.model.FieldUtil;
import com.qingshu.mapper.AlbumMapper;
import com.qingshu.service.IAlbumService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Huzz
 * @since 2021-12-09
 */
@Service
public class AlbumServiceImpl extends ServiceImpl<AlbumMapper, Album> implements IAlbumService {

    @Override
    public boolean addAlbum(Album model) {
        // 设置创建信息, 默认信息默认也是更新信息
        FieldUtil.setCreatedAndUpdateField(model);

        return this.baseMapper.insert(model) > 0;
    }

    @Override
    public Album findAlbumById(Integer albumId) {
        return this.baseMapper.selectById(albumId);
    }

    @Override
    public List<Album> findAlbumByName(String name) {
        LambdaQueryWrapper<Album> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(Album::getName, name);
        return this.baseMapper.selectList(wrapper);
    }
}
